from selenium import webdriver
from selenium.webdriver.chrome.service import Service


class UseBrowser:
    driver = None
    def __init__(self,browser_name='chrome',path='../../chromedriver.exe'):
        try:
            if browser_name.lower() =='chrome':
                options = webdriver.ChromeOptions()
                options.add_experimental_option("excludeSwitches", ["enable-automation", "enable-logging"])
                self.driver = webdriver.Chrome(executable_path=path, options=options)
                self.driver.maximize_window()
                self.driver.implicitly_wait(5)
                UseBrowser.driver = self.driver

            elif browser_name.lower() =='firefox':
                self.driver = webdriver.Firefox(executable_path=path)
                # driver_service = Service(executable_path='../geckodriver.exe')
                # self.driver = webdriver.Chrome(service=driver_service)
                self.driver.maximize_window()
                self.driver.implicitly_wait(5)
                UseBrowser.driver = self.driver
            elif browser_name.lower() =='ie':
                self.driver = webdriver.Ie(path)
        except Exception as e:
            print('browser init error!',e)
    @classmethod
    def browser_quit(cls):
        cls.driver.quit()


# if __name__ == '__main__':
#     a =UseBrowser()
    # b = UseBrowser('firefox','../geckodriver.exe')